package bairui.international.model.domain.jpa;

import com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue;

/**
 *
 * (区县)TB_Town
 *
 * @说明
 * <pre>

 * </pre>
 *
 * @see Help_TB_Town#inheritance() 继承体系信息
 *
 */
@org.hibernate.annotations.DynamicInsert
@org.hibernate.annotations.DynamicUpdate

@javax.persistence.Entity(name="t_town")
@com.lianjing.sh.processing.info.annotation.GenerateInfoModel
@SuppressWarnings("serial")
@com.lianjing.sh.model.common.annotation.Comment("区县")
@com.lianjing.sh.processing.info.annotation.InfoComment("区县")
public class TB_Town
 extends TBSuper_BaseIDAndTimeAndOrderValue
 implements 
	com.lianjing.sh.model.common.stardard.TableModel<Long>,
	java.io.Serializable

{

	
	
	/**
	 * 必须属性赋值接口
	 */
	public static interface MustProperties{
		/** 城市 */
		public bairui.international.model.domain.jpa.TB_City getCity();
		/** 名称 */
		public String getName();
		/** 代码 */
		public String getCode();
	}
	
	/**
	 * 为必须属性赋值
	 */
	public TB_Town properties(MustProperties properties) {
		this.setCity(properties.getCity());
		this.setName(properties.getName());
		this.setCode(properties.getCode());
		return this;
	}
	
	/**
	 *	必须属性构造函数
	 */
	public TB_Town(MustProperties properties) {
		this.properties(properties);
	}
	
	
	/**
	 * 可选单属性赋值接口
	 */
	public static interface OptionalSingleProperties{
		/** 分公司 */
		public bairui.international.model.domain.jpa.TB_BranchCompany getBranchCompany();
	}
	
	/**
	 * 为可选单属性赋值
	 */
	public TB_Town properties(OptionalSingleProperties properties) {
		this.setBranchCompany(properties.getBranchCompany());
		return this;
	}
	
	
	
	public TB_Town(MustProperties must, OptionalSingleProperties optionalSingle) {
		this.properties(must);
		this.properties(optionalSingle);
	}
	
	/**
	 * 仅当前必须属性赋值接口
	 */
	public static interface CurrentMustProperties{
		/** 城市 */
		public bairui.international.model.domain.jpa.TB_City getCity();
		/** 名称 */
		public String getName();
		/** 代码 */
		public String getCode();
	}
	
	/**
	 * 为仅当前必须属性赋值
	 */
	public TB_Town properties(CurrentMustProperties properties) {
		this.setCity(properties.getCity());
		this.setName(properties.getName());
		this.setCode(properties.getCode());
		return this;
	}
	
	/**
	 * 仅当前可选单属性赋值接口
	 */
	public static interface CurrentOptionalSingleProperties{
		/** 分公司 */
		public bairui.international.model.domain.jpa.TB_BranchCompany getBranchCompany();
	}
	
	/**
	 * 为仅当前可选单属性赋值
	 */
	public TB_Town properties(CurrentOptionalSingleProperties properties) {
		this.setBranchCompany(properties.getBranchCompany());
		return this;
	}
	
	public TB_Town(
		@lombok.NonNull com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue bean,
		CurrentMustProperties mustProperties,
		CurrentOptionalSingleProperties optionalProperties
	) {
		this(bean);
		this.properties(mustProperties);
		this.properties(optionalProperties);
	}
	
	public TB_Town(
		@lombok.NonNull com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue bean
	) {
		update(bean);
	}
	
	public TB_Town update(com.lianjing.sh.model.uml.model.data.TBSuper_BaseIDAndTimeAndOrderValue bean){
		this.setId(bean.getId());
		this.setCreateTime(bean.getCreateTime());
		this.setModifyTime(bean.getModifyTime());
		this.setOrderValue(bean.getOrderValue());
		return this;
	}
	
	
	/**
	 * 更新属性内部类
	 */
	public abstract class UpdateProperties {
	
		public UpdateProperties() throws Exception {
			Integer orderValue = getOrderValue(TB_Town.this);
			if(isOverride_getOrderValue){
				TB_Town.this.setOrderValue(orderValue);
			}
	
			bairui.international.model.domain.jpa.TB_City city = getCity(TB_Town.this);
			if(isOverride_getCity){
				TB_Town.this.setCity(city);
			}
	
			String name = getName(TB_Town.this);
			if(isOverride_getName){
				TB_Town.this.setName(name);
			}
	
			String code = getCode(TB_Town.this);
			if(isOverride_getCode){
				TB_Town.this.setCode(code);
			}
	
			java.util.List<bairui.international.model.domain.jpa.TB_ProxyAreaAddress> proxyAreaAddresss = getProxyAreaAddresss(TB_Town.this);
			if(isOverride_getProxyAreaAddresss){
				TB_Town.this.setProxyAreaAddresss(proxyAreaAddresss);
			}
	
			bairui.international.model.domain.jpa.TB_BranchCompany branchCompany = getBranchCompany(TB_Town.this);
			if(isOverride_getBranchCompany){
				TB_Town.this.setBranchCompany(branchCompany);
			}
	
			java.util.List<bairui.international.model.domain.jpa.TB_ProductOrder> productOrders = getProductOrders(TB_Town.this);
			if(isOverride_getProductOrders){
				TB_Town.this.setProductOrders(productOrders);
			}
		}
	
		public TB_Town up(){
			return TB_Town.this;
		}
	
		/** 排序值 */
		private boolean isOverride_getOrderValue = true;
		public Integer getOrderValue(TB_Town it) throws Exception { 
			isOverride_getOrderValue = false; 
			return null;
		}
		/** 城市 */
		private boolean isOverride_getCity = true;
		public bairui.international.model.domain.jpa.TB_City getCity(TB_Town it) throws Exception { 
			isOverride_getCity = false; 
			return null;
		}
		/** 名称 */
		private boolean isOverride_getName = true;
		public String getName(TB_Town it) throws Exception { 
			isOverride_getName = false; 
			return null;
		}
		/** 代码 */
		private boolean isOverride_getCode = true;
		public String getCode(TB_Town it) throws Exception { 
			isOverride_getCode = false; 
			return null;
		}
		/** 代理区域地址 */
		private boolean isOverride_getProxyAreaAddresss = true;
		public java.util.List<bairui.international.model.domain.jpa.TB_ProxyAreaAddress> getProxyAreaAddresss(TB_Town it) throws Exception { 
			isOverride_getProxyAreaAddresss = false; 
			return null;
		}
		/** 分公司 */
		private boolean isOverride_getBranchCompany = true;
		public bairui.international.model.domain.jpa.TB_BranchCompany getBranchCompany(TB_Town it) throws Exception { 
			isOverride_getBranchCompany = false; 
			return null;
		}
		/** 产品订单 */
		private boolean isOverride_getProductOrders = true;
		public java.util.List<bairui.international.model.domain.jpa.TB_ProductOrder> getProductOrders(TB_Town it) throws Exception { 
			isOverride_getProductOrders = false; 
			return null;
		}
	
	}
	
	
	/**
	 * 构造函数
	 */
	public TB_Town() {
	}
	
	public TB_Town(
		@lombok.NonNull Long id
	) {
		this.setId(id);
	}
	
	public TB_Town(
		@lombok.NonNull TB_Town bean
	) {
		this.setId(bean.getId());
		this.setCreateTime(bean.getCreateTime());
		this.setModifyTime(bean.getModifyTime());
		this.setOrderValue(bean.getOrderValue());
		this.setCity(bean.getCity());
		this.setName(bean.getName());
		this.setCode(bean.getCode());
		this.setProxyAreaAddresss(bean.getProxyAreaAddresss());
		this.setBranchCompany(bean.getBranchCompany());
		this.setProductOrders(bean.getProductOrders());
	}
	
	

	


	/**
	 * 属性
	 */
	@com.lianjing.sh.model.common.annotation.Comment("城市")
	@com.lianjing.sh.processing.info.annotation.InfoComment("城市")
	@com.querydsl.core.annotations.QueryInit("*.*.*")
	@javax.persistence.ManyToOne(optional=false)
	private bairui.international.model.domain.jpa.TB_City city;

	@com.lianjing.sh.model.common.annotation.Comment("名称")
	@com.lianjing.sh.processing.info.annotation.InfoComment("名称")
	@javax.persistence.Column(name="name", nullable=false, length=20)
	private String name;

	@com.lianjing.sh.model.common.annotation.Comment("代码")
	@com.lianjing.sh.processing.info.annotation.InfoComment("代码")
	@javax.persistence.Column(name="code", nullable=false, length=10)
	private String code;

	@com.lianjing.sh.model.common.annotation.Comment("代理区域地址")
	@com.lianjing.sh.processing.info.annotation.InfoComment("代理区域地址")
	@com.querydsl.core.annotations.QueryInit("*.*.*")
	@javax.persistence.OneToMany(mappedBy="town")
	private java.util.List<bairui.international.model.domain.jpa.TB_ProxyAreaAddress> proxyAreaAddresss;

	@com.lianjing.sh.model.common.annotation.Comment("分公司")
	@com.lianjing.sh.processing.info.annotation.InfoComment("分公司")
	@com.querydsl.core.annotations.QueryInit("*.*.*")
	@javax.persistence.ManyToOne()
	private bairui.international.model.domain.jpa.TB_BranchCompany branchCompany;

	@com.lianjing.sh.model.common.annotation.Comment("产品订单")
	@com.lianjing.sh.processing.info.annotation.InfoComment("产品订单")
	@com.querydsl.core.annotations.QueryInit("*.*.*")
	@javax.persistence.OneToMany(mappedBy="area")
	private java.util.List<bairui.international.model.domain.jpa.TB_ProductOrder> productOrders;

	/** get[城市] */
	public bairui.international.model.domain.jpa.TB_City getCity() {
		return this.city;
	}

	/** get[名称] */
	public String getName() {
		return this.name;
	}

	/** get[代码] */
	public String getCode() {
		return this.code;
	}

	/** get[代理区域地址] */
	public java.util.List<bairui.international.model.domain.jpa.TB_ProxyAreaAddress> getProxyAreaAddresss() {
		return this.proxyAreaAddresss;
	}

	/** get[分公司] */
	public bairui.international.model.domain.jpa.TB_BranchCompany getBranchCompany() {
		return this.branchCompany;
	}

	/** get[产品订单] */
	public java.util.List<bairui.international.model.domain.jpa.TB_ProductOrder> getProductOrders() {
		return this.productOrders;
	}

	/** set[城市] */
	public void setCity(bairui.international.model.domain.jpa.TB_City city) {
		this.city = city;
	}

	/** set[名称] */
	public void setName(String name) {
		this.name = name;
	}

	/** set[代码] */
	public void setCode(String code) {
		this.code = code;
	}

	/** set[代理区域地址] */
	public void setProxyAreaAddresss(java.util.List<bairui.international.model.domain.jpa.TB_ProxyAreaAddress> proxyAreaAddresss) {
		this.proxyAreaAddresss = proxyAreaAddresss;
	}

	/** set[分公司] */
	public void setBranchCompany(bairui.international.model.domain.jpa.TB_BranchCompany branchCompany) {
		this.branchCompany = branchCompany;
	}

	/** set[产品订单] */
	public void setProductOrders(java.util.List<bairui.international.model.domain.jpa.TB_ProductOrder> productOrders) {
		this.productOrders = productOrders;
	}

	public void assignCity(bairui.international.model.domain.jpa.TB_City city) {
		if(null != city){
			city.addTowns(this);
		}
		this.setCity(city);
	}
	


	public void assignBranchCompany(bairui.international.model.domain.jpa.TB_BranchCompany branchCompany) {
		if(null != branchCompany){
			branchCompany.addArea(this);
		}
		this.setBranchCompany(branchCompany);
	}
	


	/** add[ProxyAreaAddresss] */
	public TB_Town addProxyAreaAddresss(bairui.international.model.domain.jpa.TB_ProxyAreaAddress ... proxyAreaAddresss){
		if(this.proxyAreaAddresss == null){
			this.proxyAreaAddresss = new java.util.ArrayList<>();
		}
		for(bairui.international.model.domain.jpa.TB_ProxyAreaAddress bean : proxyAreaAddresss){
			bean.setTown(this);
			this.proxyAreaAddresss.add(bean);
		}
		return this;
	}
	/** add[ProductOrders] */
	public TB_Town addProductOrders(bairui.international.model.domain.jpa.TB_ProductOrder ... productOrders){
		if(this.productOrders == null){
			this.productOrders = new java.util.ArrayList<>();
		}
		for(bairui.international.model.domain.jpa.TB_ProductOrder bean : productOrders){
			bean.setArea(this);
			this.productOrders.add(bean);
		}
		return this;
	}
	
	/** remove[ProxyAreaAddresss] */
	public TB_Town removeProxyAreaAddresss(bairui.international.model.domain.jpa.TB_ProxyAreaAddress ... proxyAreaAddresss){
		if(this.proxyAreaAddresss == null){
			return this;
		}
		for(bairui.international.model.domain.jpa.TB_ProxyAreaAddress bean : proxyAreaAddresss){
			bean.setTown(null);
			this.proxyAreaAddresss.remove(bean);
		}
		return this;
	}
	/** remove[ProductOrders] */
	public TB_Town removeProductOrders(bairui.international.model.domain.jpa.TB_ProductOrder ... productOrders){
		if(this.productOrders == null){
			return this;
		}
		for(bairui.international.model.domain.jpa.TB_ProductOrder bean : productOrders){
			bean.setArea(null);
			this.productOrders.remove(bean);
		}
		return this;
	}
	
	/**
	 * contains[ProxyAreaAddresss]
	 *
	 * 全部输入都包含：返回 true
	 * 输入中有至少有一个不包含：返回 false
	 */
	public boolean containsProxyAreaAddresss(bairui.international.model.domain.jpa.TB_ProxyAreaAddress ... proxyAreaAddresss){
		if(this.proxyAreaAddresss == null || proxyAreaAddresss==null || proxyAreaAddresss.length<=0){
			return false;
		}
		return this.proxyAreaAddresss.containsAll(java.util.Arrays.asList(proxyAreaAddresss));
	}
	/**
	 * contains[ProductOrders]
	 *
	 * 全部输入都包含：返回 true
	 * 输入中有至少有一个不包含：返回 false
	 */
	public boolean containsProductOrders(bairui.international.model.domain.jpa.TB_ProductOrder ... productOrders){
		if(this.productOrders == null || productOrders==null || productOrders.length<=0){
			return false;
		}
		return this.productOrders.containsAll(java.util.Arrays.asList(productOrders));
	}
	

	/** take[城市] */
	public bairui.international.model.domain.jpa.TB_City takeCity(){
		if(null == this.city){
			this.city = new bairui.international.model.domain.jpa.TB_City();
		}
		return this.city;
	}
	
	/** take[分公司] */
	public bairui.international.model.domain.jpa.TB_BranchCompany takeBranchCompany(){
		if(null == this.branchCompany){
			this.branchCompany = new bairui.international.model.domain.jpa.TB_BranchCompany();
		}
		return this.branchCompany;
	}
	
	/** must[城市] */
	public bairui.international.model.domain.jpa.TB_City mustCity() {
		return this.city;
	}
	
	/** optional[分公司] */
	public java.util.Optional<bairui.international.model.domain.jpa.TB_BranchCompany> optionalBranchCompany() {
		return java.util.Optional.ofNullable(this.branchCompany);
	}
	

	/**
	 * 复写 hashCode
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		return prime * result + ((this.getId() == null) ? 0 : this.getId().hashCode());
	}
	
	/**
	 * 复写 equals
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj){
			return true;
		}
		if (obj == null){
			return false;
		}
		if (getClass() != obj.getClass()){
			return false;
		}
		TB_Town other = (TB_Town) obj;
		if (this.getId() == null) {
			return false;
		} else if (!this.getId().equals(other.getId())){
			return false;
		}
		return true;
	}
	

	/**
	 * 用来覆盖toString()的输出
	 */
	@javax.persistence.Transient
	private String toString;
	
	public void setToString(String toString) {
		this.toString = toString;
	}
	
	/**
	 * 复写 toString
	 */
	@Override
	public String toString() {
		if(null != this.toString){
			return this.toString;
		}
		String name = this.getName();
		if(null != name){
			return String.valueOf(name);
		}
		return super.toString();
	}	

	@javax.persistence.PrePersist
	public void prePersist() {
		this.setCreateTime(new java.util.Date());
		this.setModifyTime(new java.util.Date());
	}
	
	@javax.persistence.PreUpdate
	public void preUpdate() {
		this.setModifyTime(new java.util.Date());
	}



}
